/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 29489
 * Date: 2023-05-12
 * Time: 21:27
 */
import java.util.*;
interface GeneralStack<T>{
    public T push(T item);
    public T pop();
    public T peek();
    public boolean empty();
    public int size();
}
// git出问题了，我测试提交git
// git出问题了，我再次测试提交git
// git出问题了，我再次测试提交git
class ArrayListGeneralStack<T> implements GeneralStack<T>{
    ArrayList<T> list = new ArrayList<>();

    public T push(T item){
        if(item == null)
            return null;
        list.add(item);
        return item;
    }
    public T pop(){
        // if(list.size() == 0)
        //     return NULL;
        // list.remove(list.size()-1);
        if(empty())
            return null;
        list.remove(size()-1);
        return peek();
    }
    public T peek(){
        // if(list.size() == 0)
        //     return NULL;
        // return list.get(list.size()-1);
        if(empty())
            return null;
        return list.get(size()-1);
    }
    public boolean empty(){
        return list.size() == 0;
    }
    public int size(){
        return list.size();
    }
    public String toString(){
        return list.toString();
    }
    public static String getInterfaces(){
        return "interface GeneralStack";
    }
}
class Car{
    private int id;
    private String name;

    public Car(int id, String name){
        setId(id);
        setName(name);
    }
    public void setId(int id){
        this.id = id;
    }
    public void setName(String name){
        this.name = name;
    }
    public int getId(){
        return id;
    }
    public String getName(){
        return name;
    }
    @Override
    public String toString() {
        return "Car [" +
                "id=" + id +
                ", name=" + name +
                "]";
    }
}
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int m = 0;// 入栈
            int n = 0;// 出栈
            int size = 0;// 剩余元素个数
            String option = sc.nextLine();
            switch(option){
                case "quit":
                    System.exit(0);
                    break;
                case "Integer":
                    System.out.println("Integer Test");
                    ArrayListGeneralStack<Integer> st1 = new ArrayListGeneralStack<>();
                    m = sc.nextInt();// 入栈
                    n = sc.nextInt();// 出栈
                    // 入栈
                    for(int i = 0; i < m; ++i){
                        st1.push(Integer.valueOf(sc.nextInt()));
                        System.out.println("push:"+st1.peek());
                    }
                    // 出栈
                    for(int i = 0; i < n; ++i){
                        if(st1.empty())
                            // return null;
                            System.exit(0);
                        System.out.println("pop:"+st1.peek());
                        st1.pop();
                    }
                    // 打印剩余元素
                    System.out.println(st1.toString());
                    // 剩余元素出栈并累加输出
                    int sum1 = 0;
                    size = st1.size();
                    for(int i = 0; i < size; ++i){
                        sum1 += st1.peek();
                        st1.pop();
                    }
                    System.out.println("sum="+sum1);
//                    System.out.println(stack.getClass().getInterfaces()[0]);
                    System.out.println(ArrayListGeneralStack.getInterfaces());
                    break;
                case "Double":
                    System.out.println("Double Test");
                    ArrayListGeneralStack<Double> st2 = new ArrayListGeneralStack<>();
                    m = sc.nextInt();// 入栈
                    n = sc.nextInt();// 出栈
                    // 入栈
                    for(int i = 0; i < m; ++i){
                        st2.push(Double.valueOf(sc.nextDouble()));
                        System.out.println("push:"+st2.peek());
                    }
                    // 出栈
                    for(int i = 0; i < n; ++i){
                        if(st2.empty())
                            // return null;
                            System.exit(0);
                        System.out.println("pop:"+st2.peek());
                        st2.pop();
                    }
                    // 打印剩余元素
                    System.out.println(st2.toString());
                    // 剩余元素出栈并累加输出
                    double sum2 = 0.0;
                    size = st2.size();
                    for(int i = 0; i < size; ++i){
                        sum2 += st2.peek();
                        st2.pop();
                    }
                    System.out.println("sum="+sum2);
//                    System.out.println(stack.getClass().getInterfaces()[0]);
                    System.out.println(ArrayListGeneralStack.getInterfaces());
                    break;
                case "Car":
                    System.out.println("Car Test");
                    ArrayListGeneralStack<Car> st3 = new ArrayListGeneralStack<>();
                    m = sc.nextInt();// 入栈
                    n = sc.nextInt();// 出栈
                    // 入栈
                    for(int i = 0; i < m; ++i){
                        st3.push(new Car(sc.nextInt(), sc.next()));
                        System.out.println("push:"+st3.peek());
                    }
                    // 出栈
                    for(int i = 0; i < n; ++i){
                        if(st3.empty())
                            // return null;
                            System.exit(0);
                        System.out.println("pop:"+st3.peek().toString());
                        st3.pop();
                    }
                    // 打印剩余元素
                    size = st3.size();
                    for(int i = 0; i < size; ++i){
                        // System.out.println(st3.peek().toString());
                        System.out.println(st3.toString());
                        System.out.println(st3.peek().getName());
                        st3.pop();
                    }
//                    System.out.println(stack.getClass().getInterfaces()[0]);
                    System.out.println(ArrayListGeneralStack.getInterfaces());
                    break;
            }
        }
    }
}
